(require* sketch/parse/rule/common/line)
(require* sketch/parse/rule/common/block)
(require* sketch/parse/rule/common/blockx)

(defrule parallelogram-line
    "parallelogram = line, line, line, line"
    ?f1 <- (shape (name "Line") (obj ?l1))
    ?f2 <- (shape (name "Line") (obj ?l2&~?l1))
    ?f3 <- (shape (name "Line") (obj ?l3&~?l2&~?l1))
    ?f4 <- (shape (name "Line") (obj ?l4&~?l3&~?l2&~?l1))
	(test (call ShapePredicate joinsLineLine ?l1 ?l2))
	(test (call ShapePredicate joinsLineLine ?l2 ?l3))
	(test (call ShapePredicate joinsLineLine ?l3 ?l4))
  	(test (call ShapePredicate joinsLineLine ?l4 ?l1))
    (test (call ShapePredicate horizontalLine ?l1))
    (test (call ShapePredicate parallelLineLine ?l1 ?l3))
    (test (call ShapePredicate parallelLineLine ?l2 ?l4))
    (test (not (call ShapePredicate orthogonalLineLine ?l1 ?l2)))
    (test (call ShapePredicate abovePointPoint (?l1 getCenter) (?l3 getCenter)))
    (test (call ShapePredicate leftPointPoint (?l4 getCenter) (?l2 getCenter)))
    =>
    (printout "recognize parallelogram = line, line, line, line")
    (bind ?sh (new Parallelogram))
    (?sh setWidth (?l1 length))
    (?sh setHeight (?l4 length))
    (?sh setRefPoint (?l1 getCommonPointTo ?l4))
    (?sh setAngle (?l4 angleWith ?l3))
    (assert (shape
            (name "Parallelogram")
            (obj ?sh)
            (children ?l1 ?l2 ?l3 ?l4)))
    (retract ?f1)
    (retract ?f2)
    (retract ?f3)
    (retract ?f4)
    (recognize ?sh (list-children (create$ ?l1 ?l2 ?l3 ?l4))))

